package com.example.rabbitdemo.message;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PersistenceConfig {

    // 声明持久化交换机 (durable = true)
    @Bean
    public DirectExchange myExchange() {
        return new DirectExchange("my.exchange", true, false); // 参数2: durable=true
    }

    // 声明持久化队列 (durable = true)
    @Bean
    public Queue myQueue() {
        return QueueBuilder.durable("my.queue").build(); // 使用Builder方式创建持久化队列
    }

    // 绑定
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(myQueue()).to(myExchange()).with("my.routing.key");
    }
}